<template>
  <div class="auth-page">
    <div class="auth-container">
      <div class="auth-card">
        <div class="auth-header">
          <h2>登录账户</h2>
          <p>欢迎回来，请登录您的账户</p>
        </div>
        
        <a-form
          :model="formData"
          :rules="rules"
          @finish="handleSubmit"
          layout="vertical"
          class="auth-form"
        >
          <a-form-item label="邮箱" name="email">
            <a-input
              v-model:value="formData.email"
              size="large"
              placeholder="请输入邮箱地址"
              :prefix="MailOutlined"
            />
          </a-form-item>
          
          <a-form-item label="密码" name="password">
            <a-input-password
              v-model:value="formData.password"
              size="large"
              placeholder="请输入密码"
              :prefix="LockOutlined"
            />
          </a-form-item>
          
          <a-form-item>
            <a-checkbox v-model:checked="rememberMe">
              记住我
            </a-checkbox>
            <a class="forgot-link">忘记密码？</a>
          </a-form-item>
          
          <a-form-item>
            <a-button
              type="primary"
              html-type="submit"
              size="large"
              :loading="authStore.isLoading"
              block
            >
              登录
            </a-button>
          </a-form-item>
        </a-form>
        
        <div class="auth-footer">
          <p>
            还没有账户？
            <router-link to="/register">立即注册</router-link>
          </p>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { useAuthStore } from '../stores/auth'
import { message } from 'ant-design-vue'
import { MailOutlined, LockOutlined } from '@ant-design/icons-vue'

const router = useRouter()
const authStore = useAuthStore()

const formData = reactive({
  email: '',
  password: ''
})

const rememberMe = ref(false)

const rules = {
  email: [
    { required: true, message: '请输入邮箱地址' },
    { type: 'email', message: '请输入有效的邮箱地址' }
  ],
  password: [
    { required: true, message: '请输入密码' },
    { min: 6, message: '密码长度至少6位' }
  ]
}

const handleSubmit = async (values) => {
  const result = await authStore.login(values)
  
  if (result.success) {
    message.success('登录成功')
    router.push('/dashboard')
  } else {
    message.error(result.message)
  }
}
</script>

<style scoped>
.auth-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-container {
  width: 100%;
  max-width: 400px;
}

.auth-card {
  background: white;
  border-radius: 12px;
  padding: 40px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.auth-header {
  text-align: center;
  margin-bottom: 32px;
}

.auth-header h2 {
  font-size: 24px;
  font-weight: 600;
  color: #333;
  margin-bottom: 8px;
}

.auth-header p {
  color: #666;
  margin: 0;
}

.auth-form {
  margin-bottom: 24px;
}

.forgot-link {
  float: right;
  color: #1890ff;
  text-decoration: none;
}

.auth-footer {
  text-align: center;
  border-top: 1px solid #f0f0f0;
  padding-top: 24px;
}

.auth-footer p {
  margin: 0;
  color: #666;
}

.auth-footer a {
  color: #1890ff;
  text-decoration: none;
  font-weight: 500;
}

@media (max-width: 480px) {
  .auth-card {
    padding: 24px;
  }
}
</style> 